using System;
using System.Collections.Generic;

namespace NobleTech.Products.CreatureKingdom.Utils
{
    public static class Misc
    {
        public delegate TOutput FoldLFn<TOutput, TListType>(TOutput arg1, TListType arg2);

        public static TOutput foldl<TOutput, TListType>(
            FoldLFn<TOutput, TListType> fn, TOutput x, IEnumerable<TListType> list)
        {
            foreach (TListType listItem in list)
                x = fn(x, listItem);
            return x;
        }

        public static double NormaliseAngle(double Angle)
        {
            return (Angle + 2 * Math.PI) % (2 * Math.PI);
        }

        public static bool CmpDbl(double a, double b)
        {
            return Math.Abs(a - b) < Math.Max(Math.Abs(a), Math.Abs(b)) / 10000;
        }
    }
}
